import { EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IGroupMoneyOption } from "./NormalGroupMoneyStrategy";
import { IMoneyStrategy } from "../IMoneyStrategy";

export class NormalGroupMoneyStrategyV2 implements IMoneyStrategy {
    option: IGroupMoneyOption;
    start: boolean = false;
    startIndex: number = 0;
    constructor(name: string, option?: IGroupMoneyOption) {
        this.strategyName = name;
        if (option) {
            this.option = option;
        }
        else {
            this.option = {
                groupCount: 1,
                addStep: 100,
                devideStep: -100,
                maxLevel:3000,
                reverse: false,
            };
        }
        this.resetStrategy();
    }
    showMoney(): [EnumBjlResult, number] {
        throw new Error("Method not implemented.");
    }
    resetRecm(): void {
    }
    resetStrategy(): void {
        this.start = false;
        this.startIndex = 0;
    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let recmV = roundInfo.userRecm;
        if (!this.start)
            return [EnumBjlResult.U, recmInfo.recmMoney];
        if (recmV == EnumBjlResult.U)
            return [recmV, recmInfo.recmMoney];

        let recmMoney = 0;
        if (userRecm.roundSummaryInfo.winCount == userRecm.roundSummaryInfo.failCount) {
            recmV = EnumBjlResult.U;
            recmMoney = 0;
        }
        else if (userRecm.roundSummaryInfo.winCount > userRecm.roundSummaryInfo.failCount) {
            recmV = roundInfo.userRecm;
            recmMoney = (userRecm.roundSummaryInfo.winCount - userRecm.roundSummaryInfo.failCount) * baseMoney;
        }
        else if (userRecm.roundSummaryInfo.winCount < userRecm.roundSummaryInfo.failCount) {
            recmV = roundInfo.userRecm == EnumBjlResult.Z ? EnumBjlResult.X : EnumBjlResult.Z;
            recmMoney = (userRecm.roundSummaryInfo.failCount - userRecm.roundSummaryInfo.winCount) * baseMoney;
        }
        else {
            recmV = EnumBjlResult.U;
            recmMoney = 0;
        }
        return [recmV, recmMoney];
    }
    strategyName: string;
    debugCompoenent: string = "";
    copyValue(valueObj: any): void {
        let obj = valueObj as NormalGroupMoneyStrategyV2;
        if (obj) {
            //复制
            this.start = obj.start;
        }
    }

}